#!/bin/python
# coding: utf-8
import json
import sys
import urllib2

#默认编码utf-8
reload(sys)
sys.setdefaultencoding('utf8')

corpid = 'wx40aaada1955e3fea'
corpsecret = 'oELU94oE6G_X1yzGj9peGQ4Wiuh9MTp1SeSPFpfA0JeQnV6jUQkhWldKr47hat0X'
gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret
token_file = urllib2.urlopen(gettoken_url)
token_data = token_file.read().decode('utf-8')
token_json = json.loads(token_data)
token_json.keys()
token = token_json['access_token']


def send_data(user, subject, content):
	send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + token
	send_values = {
		"touser":'@all',
		"toparty":"1",
		"msgtype":"text",
		"agentid":"1",
		"text":{
		"content":subject + '\n' + content
		},
		"safe":"0"
		}

	send_data = json.dumps(send_values, ensure_ascii=False)
	#send_data = simplejson.dumps(send_values, ensure_ascii=False).encode('utf-8')
	send_request = urllib2.Request(send_url, send_data)
	response = json.loads(urllib2.urlopen(send_request).read())
	#a = json.loads(response.read())
	#print response
if __name__ == '__main__':
	send_data(sys.argv[1],sys.argv[2],sys.argv[3])
